
var interval;
var delay = 3500;

function getText()
{
    return document.getElementById(txtctrl);
}
function getFilename(path)
{
    var a = path.split("/");
    return a[a.length-1];
}
function getCurrentImagePosition(id)
{
    var e = document.getElementById(id);
    if (e.tagName.toLowerCase() == "img") 
    {
        for (var i=0; i < img.length; i+=3)
        {
            if (getFilename(e.src) == getFilename(img[i]))
            {
                return i;
            }
        }
        return false;
    }
    else 
    {
        return false;
    }
}
function getNextImagePosition(id)
{
    var i  = getCurrentImagePosition(id);

    if (i == (img.length - 3))
    {
        return 0;
    }
    else
    {
        return i+3;
    }
}
function getPreviousImagePosition(id)
{
    var i = getCurrentImagePosition(id);

    if (i == 0)
    {
        return img.length - 3;
    }
    else
    {
        return i-3;
    }
}
function loadNextImage(id)
{
    var e = document.getElementById(id);
    var t = getText();
    var i = new Image();
    i.src = img[getNextImagePosition(id)];
    i.onload = new function(){ 
        e.src = i.src; 
        t.innerHTML = img[getCurrentImagePosition(id)+1]; 
        e.alt = img[getCurrentImagePosition(id)+1]; 
    }
}
function loadPreviousImage(id)
{
    var e = document.getElementById(id);
    var t = getText();
    var i = new Image();
    i.src = img[getPreviousImagePosition(id)];
    i.onload = new function(){ 
        e.src = i.src; 
        t.innerHTML = img[getCurrentImagePosition(id)+1]; 
        e.alt = img[getCurrentImagePosition(id)+1]; 
    }
}
function GoToURL(id)
{
    var e = document.getElementById(id);
    var j=-1;
    for (var i=0; i < img.length; i+=3)
    {
        if (getFilename(e.src) == getFilename(img[i]))
        {
            j=i+2;
        }
    }
    if (j>0)
        window.location.href=img[j]; 
}
